package org.offsync.util

class AutoDisposed[T <: Disposable](val ref: T) extends Disposable {
  var ownership: Disposable = ref
  
  def disposeState: DisposeState = ownership.disposeState
  
  def dispose(): Unit = ownership.dispose()
  
  def waitDisposed(
      deadline: Time = Never): Unit = ownership.waitDisposed(deadline)
  
  def release(): T = try ref finally ownership = Disposed
}
